<?php
/*
 * @Date: 2020-05-03 22:03:52
 * @名称: 
 * @版本: 0.01
 * @作者: 初雪桜
 * @邮箱: 202184199@qq.com
 * @最后编辑人: 初雪桜
 * @LastEditTime: 2021-01-29 13:28:50
 * @FilePath: /Site/app/useradmin/controller/Edit.php
 */

namespace app\useradmin\controller;

use app\BaseController;
use app\useradmin\controller\Comics\Get\GetComicsInfo;
use app\useradmin\controller\Comics\Get\GetComicsProjectImagesList;
use app\useradmin\controller\Comics\Operation\ComicsEditProject;
use app\useradmin\controller\Comics\Operation\ComicsSaveProject;

class Edit extends BaseController
{
    /**
     * @方法名: 修改分卷内容
     * @作者: 初雪桜
     * @信息: 修改分卷内容
     * @param {String} $bookId 书籍id
     * @param {String} $projectId 分卷id
     * @param {String} $time 时间戳
     * @param {String} $hashHmac_bookId sha512后的书籍id
     * @param {String} $hashHmac_projectId sha512后的分卷id
     * @return {html}
     */
    public function EditProject()
    {
        /*  $bookId =  "58218e5a5f6b9a4f93e242bb";
        $projectId =  "58218e605f6b9a4f93e244c1"; */
        $bookId =  input("post.bookId");
        $projectId =  input("post.projectId");
        $time =  time();
        $hashHmac_bookId = hash_hmac("sha256", $bookId . $time, config("useradminConfig.useradmin_Edit_sha256Encryption")); //加密后
        $hashHmac_projectId = hash_hmac("sha256", $projectId . $time, config("useradminConfig.useradmin_Edit_sha256Encryption")); //加密后
        $ComicsEditProject = new ComicsEditProject($this->app);
        return $ComicsEditProject->EditProject($bookId, $projectId, $time, $hashHmac_bookId, $hashHmac_projectId);
    }
    /**
     * @方法名: 获取分卷内容图片列表
     * @作者: 初雪桜
     * @信息: 获取分卷内容图片列表
     * @param null
     * @return json
     */
    public function getImagesList()
    {
        /*   $time = "1595577314";
        $encryption_bookId = "716e7cefb9d5da18b246f3468e8434d74a1c80de6969f5f295ccd48cc393ca22";
        $encryption_projectId = "d6bbc732177373d6ec73b8e6027c4964c72838dbe55dae79da29be6cb7b79a2a";
        $bookId = "582186a35f6b9a4f93dcb549";
        $projectId = "582186a35f6b9a4f93dcb54b"; */
        $time = input('post.time'); //@ 时间戳
        $encryption_bookId = input('post.encryption_bookId'); //@ 书籍id 加密后
        $encryption_projectId = input('post.encryption_projectId'); //@ 章节id 加密后
        $bookId = input('post.bookId'); //@ 书籍id 加密前
        $projectId = input('post.projectId'); //@ 章节id 加密前
        $hashHmac_bookId = hash_hmac("sha256", $bookId . $time, config("useradminConfig.useradmin_Edit_sha256Encryption")); //加密后
        $hashHmac_projectId = hash_hmac("sha256", $projectId . $time, config("useradminConfig.useradmin_Edit_sha256Encryption")); //加密后
        $GetComicsProjectImagesList = new GetComicsProjectImagesList($this->app);
        return $GetComicsProjectImagesList->GetImageList($time, $encryption_bookId, $encryption_projectId, $bookId, $projectId, $hashHmac_bookId, $hashHmac_projectId);
    }
    /**
     * @方法名: 保存漫画分卷信息
     * @作者: 初雪桜
     * @信息: 主要用来保存新上传的图片
     * @param Null
     * @return Json
     */
    public function SubmissionProjectData() //提交章节数据
    {
        $projectName = input('post.projectName'); //@ 分卷名称
        $subsection = input('post.subsection'); //@ 分卷编号
        $time = input('post.time'); //@ 时间戳
        $encryption_bookId = input('post.encryption_bookId'); //@ 书籍id 加密后
        $encryption_projectId = input('post.encryption_projectId'); //@ 章节id 加密后
        $bookId = input('post.bookId'); //@ 书籍id 加密前
        $projectId = input('post.projectId'); //@ 章节id 加密前
        $imageList = input('post.imageList'); //@ 图片列表
        $hashHmac_bookId = hash_hmac("sha256", $bookId . $time, config("useradminConfig.useradmin_Edit_sha256Encryption")); //加密后
        $hashHmac_projectId = hash_hmac("sha256", $projectId . $time, config("useradminConfig.useradmin_Edit_sha256Encryption")); //加密后
        $ComicsSaveProject = new ComicsSaveProject($this->app);
        return $ComicsSaveProject->SaveProject($projectName, $subsection, $time, $encryption_bookId, $encryption_projectId, $bookId, $projectId, $imageList, $hashHmac_bookId, $hashHmac_projectId);
    }
    /**
     * 编辑漫画信息
     * @param post bookId
     * @return void
     */
    public function GetEditComicsInfo()
    {
        $token = cookie("Authorization"); //@q 用户token
        $userTokenVerificationParse = ParseUserToken($token, true); //@q 用户token验证
        if ($userTokenVerificationParse['code'] != 200) { //@q 用户token 验证失败
            return json($userTokenVerificationParse);
        }
        $user_info = $userTokenVerificationParse["data"]["user_info"]; //@q 用户token解析用户信息
        $time =  time(); //@q 时间戳
        $bookId =  input('post.bookId'); //@i 书籍id
        // $bookId =  "book-pasbsr-r64gie46tenrzee33wpmkap8wp1u6umop0segvnfdaugflkwsxcz5jxbjtzxcxyflim2e38pz6ufxuekp4ssxkarc3cnce9ojmwbuf6v41imb9cwo0jb";
        $hashHmac_bookId = hash_hmac("sha256", $bookId . $time, config("useradminConfig.useradmin_Edit_EditComicsInfo_sha256Encryption")); //加密后 加密id
        $hashHmac_toKen = hash_hmac("sha256", $token . $bookId . $time, config("useradminConfig.useradmin_Edit_EditComicsInfo_sha256Encryption")); //加密后 加密id

        $GetComicsInfo = new GetComicsInfo($this->app);
        return $GetComicsInfo->GetComicsInfo($user_info, $time, $bookId, $hashHmac_bookId, $hashHmac_toKen);
    }
}
